﻿using System.Web;
using Ninject;
using Ninject.Parameters;

namespace Nydus.WebForms.FrontendModel
{
    public class NinjectPresenterFactory : BasePresenterFactory
    {
        public NinjectPresenterFactory(IKernel kernel)
        {
            this.kernel = kernel;
        }

        public override object GetPresenter(HttpContextBase httpContextBase, BasePage page)
        {
            var presenterType = GetPresenterType(page);

            var parameters = new IParameter[]{
                new ConstructorArgument("view", page),
                new ConstructorArgument("context", httpContextBase),
            };

            return kernel.Get(presenterType, parameters);
        }

        private IKernel kernel;
    }
}
